// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    string:'',
    content:[]

  },
  del: function (e) {
    var id = e.currentTarget.dataset.index;
    console.log(id)
    var that = this;
      wx.request({
        url: 'http://localhost:8082/order/delete',// 仅为示例，并非真实的接口地址
        method: 'post',
        data: {
          id:id
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success(res) {
          wx.hideLoading();
          console.info(res.data);
          if (res.data['msg'] == "成功") {
            that.onLoad()
            // wx.redirectTo({
            //   url: '../order/order'
            // })
          } else {
            wx.showToast({
              title: res.data['msg'],
              icon: 'none',
              duration: 2000
            })
          }
        }

      })
    },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var s= new Array()
    var Authorization = wx.getStorageSync('token');
    if (Authorization == '') {
      wx.setStorageSync('jwtMessage', "认证信息已过期，请重新登录");
      wx.reLaunch({
        url: '/pages/openid/openid',
      })
    } else {
      that.setData({
        Authorization: Authorization,
      })
    }
    wx.request({
      url: "http://localhost:8082/order/userlist",
      method: "GET",
      header: {
        "content-type": "application/x-www-form-urlencoded",
        'Authorization': wx.getStorageSync('token')
      },
      data: {
        userID:wx.getStorageSync('userID')
      },
      success: function (res) {
        console.log(res);
        
        if (res.statusCode == 200) {
          
          //s=JSON.parse(that.orderList),
          console.log(JSON.parse(res.data.data[0].content))
          for (var i in res.data.data) {
            console.log(JSON.parse(res.data.data[i].content))
            s.push(JSON.parse(res.data.data[i].content)) 
          }
          console.log(s)
        that.setData({
          orderList: res.data.data,
          content:s            
        })
        console.log(res.data.data)
          
        }else {
          wx.setStorageSync('jwtMessage', "认证信息已过期，请重新登录");
          wx.reLaunch({
            url: '/pages/openid/openid',
          })
        }

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.onLoad()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
this.onLoad()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})